import Vue from 'vue'
import VueRouter from 'vue-router'

import TopAndSide from '@/pages/TopAndSide.vue'
import StudentInfo from '@/pages/StudentInfo.vue'
import Schedule from '@/pages/Schedule.vue'
import Home from '@/pages/Home.vue'
import OptionalCourese from '@/pages/OptionalCourese.vue'
import SelectedCourese from '@/pages/SelectedCourese.vue'
import Post from '@/pages/Post.vue'
import Comment from '@/pages/Comment.vue'
import unHander from '@/pages/unHander.vue'
import Adminer from '@/pages/Adminer.vue'
import ChangePassword from '@/pages/ChangePassword.vue'
import Userregister from '@/pages/Userregister.vue'
import Data from '@/pages/Data.vue'
import Userlogout from '@/pages/Userlogout.vue'
import AboutView from '@/pages/AboutView.vue'
import Login from '@/pages/Login.vue'
import AdminLogin from '@/pages/AdminLogin.vue'

Vue.use(VueRouter)

const routes = [
    {
        path: '/',
        component: TopAndSide,
        children: [
            {
                path: 'studentInfo', component: StudentInfo
            },
            {
                path: 'curriculum_admin', name: 'Comment', component: () => import( '../pages/CurriculumAdmin'),
            },
            {
                path: 'StudentsSelectedCourse', name: 'studentsselectedcourse', component: () => import( '../pages/StudentsSelectedCourse'),
            },
            {
                path: 'students_admin', name: 'User', component: () => import( '../pages/StudentsAdmin'),
            },
            {
                path: 'schedule', component: Schedule
            },
            {
                path: 'optionalCourese', component: OptionalCourese
            },
            {
                path: 'selectedCourese', component: SelectedCourese
            },
            {
                path: 'post', name: 'Post', component: Post
            },
            {
                path: 'comment', name: 'Comment', component: Comment
            },
            {
                path: 'unhander', name: 'unHander', component: unHander
            },
            {
                path: 'adminer', name: 'Adminer', component: Adminer
            },
            {
                path: 'change_password', name: 'ChangePassword', component: ChangePassword
            },
            {
                path: 'userregister', name: 'Userregister', component: Userregister
            },
            {
                path: 'date', name: 'Date', component: Data
            },
            {
                path: 'userlogout', name: 'Userlogout', component: Userlogout
            }
        ]
    },
    {
        path: '/about',
        component: AboutView
    },
    {
        path: '/login',
        component: Login
    },
    {
        path: '/adminLogin',
        component: AdminLogin
    },
]

const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes
})

// router.beforeEach((to, from, next) => {
//     if (to.name !== "Login") {
//         if (!localStorage.getItem("aname") || !localStorage.getItem("apassword")) {
//             alert("请先登录！")
//             next({name: 'Login'});
//         }
//     }
//     next();
// })

// 全局后置钩子
router.afterEach(to => {
    // 设置title
    document.title = "学生选课系统";
})

export default router
